Xbasic

Matching Clauses in Regular Expressions

Description

A list of various matching clauses in regular expressions with descriptions of their meanings and examples of their use.

\d

  • Any digit from 0 to 9

    \d\d matches 59, but not ab or 5a

\D

  • Any character not a digit

    \D\D\D matches abc, but not 123 or 12b

\w

  • Any word character: A-Z, a-z, 0-9, and underscore "_"

    \w\w\w\w matches 12a4, but not $123

\W

  • Any non-word character

    \W matches $, but not A

\s

  • Any white space character, including tab, newline, carriage return, formfeed, and vertical tab

    \s matches the tab character, but not A

\S

  • Any non-white space character

    \S matches A, but not the tab character

.

  • Any single character

    . matches a, 1, and $

...

  • Any one of the characters between the brackets

    abc matches a, b, or c
    a-z matches any character a through z

^...

  • Any one character not between the brackets

    abc matches any character except a, b, or c
    a-z matches any character except a through z

\<

  • The NULL string at the start of a word.

\>

  • The NULL string at the end of the word.

\b

  • The NULL string at either the start or the end of a word.

\B

  • A NULL string within a word.

Example

This example looks for a telephone number. The area code must be enclosed in parentheses and there also must be a hyphen.

? regex_split("Our phone number is (781)229-4500.", "(\(\d\d\d\)\d\d\d-\d\d\d\d)")
= "(781)229-4500"

This example looks for the area code telephone number.

? regex_split("Our phone number is (781)229-4500.", "(\(\w\w\w\))")
= "(781)"

This example looks for value of a dollar amount. Note that the "\" before the period "." indicates that the period is the actual character being looked for.

? regex_split("the price is $123.45.", "(\d\d\d\.\d\d)")
= "123.45"

See Also